/* 全局变量 */
//当前网页的路径
var arr = window.location.pathname.split("/");
var urlFilename = arr[arr.length - 1].substring(0, arr[arr.length - 1].lastIndexOf("."));
//截取dmc
var dmc = urlFilename.substring(0, urlFilename.indexOf("_"));
var pid = sessionStorage.getItem("enterProjectId");
var dmid = sessionStorage.getItem("dmid");
var baseApi = parent.parent.IP || '';
var seachInputValue = ''; // 搜索框值
var seachValueNum = 0;
var seachValueCurrentNum = 1;

var createBy = localStorage.getItem("username");
var dataPacketFileName = localStorage.getItem('dataPacketFileName');
var dataModuleName = localStorage.getItem('dataModuleName');
var dataModuleFileName = localStorage.getItem('dataModuleFileName');

/* 为每个节点添加id */
var element = [];
element = $("body").find("*");
for (var i = 0; i < element.length; i++) {
  $(element[i]).attr("ids", "ids-" + (i + 1));
}

var html = `

<div class="search_box_f">
    <div class="search-btn-flex" onclick="searchDivHide()" title="页面搜索收起"><img src="./img/shousuo_b.png"/></div>
    <div id="searchDiv">
        <div class="searchDiv_div">
          <input class="seach-input" type="text" id="seachKey" value="" placeholder="请输入关键字" />
        </div>
        <button id="searchContent" class="search-button">搜索并高亮显示</button>
        <div id="search_info" style="display: none;">
          <span id="seach_value_num">第0项, 共0项</span>
          <button id="top_search" class="searchPro-but">上一项</button>
          
          <button id="bottom_search" class="searchPro-but">下一项</button>
          <span id="close_seach">
            <svg t="1724935334282" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4443" width="32" height="32"><path d="M286.165333 798.165333L512 572.330667l225.834667 225.834666 60.330666-60.330666L572.330667 512l225.834666-225.834667-60.330666-60.330666L512 451.669333 286.165333 225.834667 225.834667 286.165333 451.669333 512l-225.834666 225.834667z" fill="" p-id="4444"></path></svg>
            
          </span>
        </div>
    </div>
    </div>
`
$(".lbody").prepend(html);

sessionStorage.setItem("bodyValue", $("body")[0])
var old = "";

var searchContentDom = $("body #content")[0];
var searchContentDom1 = null;
// var parentSearch = $('#key', parent.document).val().trim();
var parentSearch = '';
$(document).on('click', '#searchContent', function () {
  var val = $("#seachKey").val();
  seachInputValue = val;
  seachValueNum = 0;
  if (val != null && val.trim() != "" && val.trim() != ".") {
    findText(val.trim(), '#a1ff73');
  }
})

$(document).on('click', '#close_seach', function () {
  $("#search_info").hide();
})

$(document).on('click', '#bottom_search', function () {
  if (!seachValueNum) return;
  seachValueCurrentNum++
  if (seachValueCurrentNum > seachValueNum) {
    seachValueCurrentNum = 1;
  }
  $(".seach_item").removeClass('seach_current');
  var anchorElement = document.getElementById("section" + seachValueCurrentNum);

  console.log(anchorElement, '如果找到了对应的锚点元素，则滚动到该元素位置', seachValueCurrentNum);
  // 如果找到了对应的锚点元素，则滚动到该元素位置
  if (anchorElement) {
    anchorElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
    // 调整滚动位置以确保元素在视口内
    var offset = 100; // 根据需要调整的偏移量
    var elementPosition = anchorElement.getBoundingClientRect().top + window.scrollY;
    var offsetPosition = elementPosition - offset;
    window.scrollTo({
      top: offsetPosition,
      behavior: 'smooth'
    });
    $("#section" + seachValueCurrentNum).addClass('seach_current')
    $("#seach_value_num").html('第' + seachValueCurrentNum + '项, 共' + seachValueNum + '项');
  }
})

$(document).on('click', '#top_search', function () {
  if (!seachValueNum) return;
  seachValueCurrentNum--
  if (seachValueCurrentNum < 1) {
    seachValueCurrentNum = seachValueNum;
  }
  $(".seach_item").removeClass('seach_current');
  var anchorElement = document.getElementById("section" + seachValueCurrentNum);

  console.log(anchorElement, '如果找到了对应的锚点元素，则滚动到该元素位置', seachValueCurrentNum);
  // 如果找到了对应的锚点元素，则滚动到该元素位置
  if (anchorElement) {
    anchorElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
    // 调整滚动位置以确保元素在视口内
    var offset = 100; // 根据需要调整的偏移量
    var elementPosition = anchorElement.getBoundingClientRect().top + window.scrollY;
    var offsetPosition = elementPosition - offset;
    window.scrollTo({
      top: offsetPosition,
      behavior: 'smooth'
    });
    $("#section" + seachValueCurrentNum).addClass('seach_current')
    $("#seach_value_num").html('第' + seachValueCurrentNum + '项, 共' + seachValueNum + '项');
  }
})



//显示隐藏页面搜索
function searchDivHide() {
  if ($(".search-btn-flex img").attr("src") == "./img/shousuo_b.png") {
    $(".search-btn-flex img").attr("src", "./img/zhankai_b.png");
    $(".search-btn-flex").css("position", "relative");
    $("#searchDiv").css("display", "none");
    $(".search_box_f").css("background", "#ffffff00");
  } else {
    $(".search-btn-flex img").attr("src", "./img/shousuo_b.png");
    $(".search-btn-flex").css("position", "relative");
    $("#searchDiv").css("display", "inline-block");
    $(".search_box_f").css("background", "#ffffff");
  }
}

function findText(searchVal, bgColor) {
  console.log(searchVal);
  var oDiv = searchContentDom;
  if (searchContentDom1) {
    oDiv.innerHTML = searchContentDom1;
  }
  var sText = oDiv.innerHTML;
  if (!searchContentDom1) {
    searchContentDom1 = sText;
  }

  // 去掉 script 标签，防止乱码
  var reg1 = /<script[^>]*>([\s\S]*?)<\/script>/gi;
  sText = sText.replace(reg1, "");

  // 去除空格标签
  var reg2 = /&nbsp;/gi;
  sText = sText.replace(reg2, " ");

  // 移除之前的高亮标签
  var re = new RegExp(
    '<span\\s+id="[^"]*"\\s+class="[^"]*"\\s+name="addSpan"\\s+style="background-color: red;">' + old + '</span>',
    "gim"
  );
  sText = sText.replace(re, old);

  if (parentSearch != null && parentSearch.trim() != "" && parentSearch != undefined) {
    var re = new RegExp(
      '<span\\s+id="[^"]*"\\s+class="[^"]*"\\s+name="addSpan"\\s+style="background-color: red;">' + parentSearch + '</span>',
      "gim"
    );
    sText = sText.replace(re, parentSearch);
  }

  var bgColor = bgColor || "orange";
  var num = -1;

  // 匹配传入的搜索值，不区分大小写
  var rStr = new RegExp(searchVal, "gi");

  // 匹配 HTML 元素（支持多行标签）
  var rHtml = new RegExp("<[\\s\\S]*?>", "gi");

  // 存放 HTML 元素的数组
  var aHtml = sText.match(rHtml);
  var arr = sText.match(rStr);
  var a = -1;

  // 替换 HTML 标签
  sText = sText.replace(rHtml, "{~}");
  console.log(sText, "231839173017930");

  sText = sText.replace(rStr, function () {
    console.log("替换html标签");
    seachValueNum++;
    a++;
    return (
      "<span id=" +
      "section" +
      seachValueNum +
      " class='seach_item' name='addSpan' style='background-color: " +
      bgColor +
      ";'>" +
      arr[a] +
      "</span>"
    );
  });

  // 恢复 HTML 标签
  sText = sText.replace(/{~}/g, function () {
    num++;
    return aHtml[num];
  });

  oDiv.innerHTML = sText;
  old = searchVal;

  $("#seachKey").val(seachInputValue);
  if (seachValueNum > 0) {
    $("#search_info").show();
    $("#seach_value_num").html("第1项, 共" + seachValueNum + "项");
    $("#section" + seachValueCurrentNum).addClass("seach_current");
  } else {
    $("#search_info").show();
    $("#seach_value_num").html("第0项, 共0项");
  }
}


/* 长按添加气泡 */
//屏蔽浏览器右键菜单
document.oncontextmenu = function () {
  return false;
}
/* 右键菜单 */
var menuHtml = '<div class="context-menu">';
menuHtml += '<ul>';
menuHtml += '<li><a href="javascript:;" class="menu_a">备注</a></li>';
menuHtml += '</ul>';
menuHtml += '</div>';
$("body").append(menuHtml);

/* 右键事件 == 长按事件 */
var $ids = "";//右键选中的节点
$("body").mousedown(function (e) {
  if (3 == e.which) {
    //获取右键点击坐标
    var x = e.clientX + $(window).scrollLeft();
    var y = e.clientY + $(window).scrollTop();
    $('.context-menu').show().css({ left: x, top: y });
    $ids = $(e.target);
  }
})
var timeOutEvent;
$("body").on('touchstart', function (e) {
  //防止同类型事件同时执行
  e.stopImmediatePropagation();
  //获取右键点击坐标
  var _touch = e.originalEvent.targetTouches[0];
  var x = _touch.clientX + $(window).scrollLeft();
  var y = _touch.clientY + $(window).scrollTop();
  // 长按事件触发
  timeOutEvent = setTimeout(function () {
    // timeOutEvent = 0;
    $('.context-menu').show().css({ left: x, top: y });
    $ids = $(e.target);
  }, 1000);
})
$("body").on('touchmove', function (e) {
  //防止同类型事件同时执行
  e.stopImmediatePropagation();
  $('.context-menu').hide();
  clearTimeout(timeOutEvent);
})


//点击任意部位隐藏
$(document).on('click', function () {
  $('.context-menu').hide();
  clearTimeout(timeOutEvent);
})

/* 处理不能有气泡的标签 */
var nodeParents = [".warning", ".caution", ".note", ".headline", ".btn-step", "requirementTitle", ".fault", ".fault-quiz", ".btn-action", ".stepheadline", ".DmMedialist_div"];

/* 添加气泡 */
$(".context-menu .menu_a").on("click", function () {
  clearTimeout(timeOutEvent);
  //处理多媒体添加备注
  if ($ids.parents().is(".multimedia")) {
    $ids = $ids.parents(".multimedia");
  }
  if ($ids.parents().is(".figure")) {
    $ids = $ids.parents(".figure");
  }

  if ($ids.parents()[0].tagName == "LI" || $ids.parents()[0].tagName == "li") {
    $ids = $ids.closest("li");
  }

  /* 处理不能有气泡的标签 */
  for (var i = 0; i < nodeParents.length; i++) {
    if ($ids.parents().is(nodeParents[i]) || $ids.is(nodeParents[i])) {
      layer.msg(i18n("i18n-alert-noRemark"));
      $('.context-menu').hide();
      $ids = "";
      return false;
    }
  }
  if ($ids.parent().is(".content") || $ids[0].tagName == "TH" || $ids[0].tagName == "th"
    || $ids[0].tagName == "TD" || $ids[0].tagName == "td" || $ids[0].tagName == "A" || $ids[0].tagName == "a") {
    layer.msg(i18n("i18n-alert-noRemark"));
    $('.context-menu').hide();
    $ids = "";
    return false;
  }
  if ($ids != "") {
    if ($ids.prev().attr("id") == $ids.attr("ids")) {
      layer.msg(i18n("i18n-alert-hasRemark"));
      $('.context-menu').hide();
      $ids = "";
      return false;
    }
    var bubble = '<div class="bubble" style="z-index:1;cursor: text;" id="' + $ids.attr("ids") + '">';
    bubble += '<input type="hidden" class="bubble-id" value=""> ';
    bubble += '<div class="bubble-input" contenteditable="true" style="color:black;"></div>';
    bubble += '<div class="bubble-btn">' +
      '<button type="button" class="hide btn btn-lg btn-danger">隐藏</button>' +
      '<button type="button" class="delete btn btn-lg btn-danger">' + i18n("i18n-lan-delete") + '</button>' +
      '<button type="button" class="save btn btn-lg btn-success">' + i18n("i18n-lan-save") + '</button></div>';
    bubble += '</div>';
    $ids.append(bubble);

  }
})

//xtt添加的评论功能
$(".context-menu .menu_b").on('click', function () {
  $('.context-menu').hide();
  parent.openMessage();
})

//xtt添加的打印功能
$(".context-menu .menu_c").on('click', function () {
  $('.context-menu').hide();
  parent.doPrint();
})

$(".context-menu .menu_d").on("click", function () {
  var url = $("#dateModelView").context.URL;
  parent.addBookRemark(url, dmc);
})
/* 保存备注 */
$("body").on("click", ".bubble-btn>.save", function (e) {

  var createBy = localStorage.getItem("username");
  var dataPacketFileName = localStorage.getItem('dataPacketFileName');
  var dataModuleName = localStorage.getItem('dataModuleName');
  var dataModuleFileName = localStorage.getItem('dataModuleFileName');

  //防止同类型事件同时执行
  e.stopImmediatePropagation();

  var _this = $(this);
  var url = baseApi + "/ietm/remarks/add";
  var remarksPosition = $(this).parent(".bubble-btn").parent(".bubble").attr("id");
  var remarkContent = $(this).parent(".bubble-btn").parent(".bubble").parent().clone().children().remove().end().text();
  var content = $(this).parent(".bubble-btn").prev(".bubble-input").html();
  var id = $(this).parent(".bubble-btn").parent(".bubble").find(".bubble-id").val();
  var type = '0';
  var modeType = sessionStorage.getItem("myScheme");
  var mic = sessionStorage.getItem("projectName");
  var pid = "";
  if (!content) {
    layer.msg("请输入备注内容！");
    return false;
  }
  if (modeType == "0") {
    pid = sessionStorage.getItem("currentPid");
  } else {
    pid = sessionStorage.getItem("enterProjectId");
  }
  if (createBy == null || createBy == '') {
    createBy = "admin";
  }
  console.log(id, '2818301-038-183-8');
  if (id == '') {
    // 新增
    $.ajax({
      type: "POST",
      url: url,
      data: {
        "dataPacketFileName": dataPacketFileName,
        "dataModuleFileName": dataModuleFileName,
        "dataModuleName": dataModuleName,
        "remarksPosition": remarksPosition,
        "createBy": createBy,
        "remarksContent": content
        //  

        // "content": content,
        // "createBy": createBy,
        // "id": id,
        // "modeType" : modeType,
        // "mic":mic 
      },
      dataType: "JSON",
      success: function (res) {
        if (res.code == 200) {
          layer.msg("添加成功 !");
          _this.parent(".bubble-btn").parent(".bubble").find(".bubble-id").val(res.data[res.data.length-1].id);
          _this.hide();
          // _this.prev(".delete").hide();
          _this.siblings(".delete, .hide").hide();
        } else {
          if (res.msg.includes("未登录")) {
            layer.msg('用户未登录!');
            setTimeout(function () {
              parent.parent.wlogout()
            }, 1500);
            return false;
          } else {
            layer.msg('添加失败 !');
          }
        }
      }, error: function (err) {
        layer.msg('添加失败 !');
      }
    })
  } else {
    $.ajax({
      type: "POST",
      url: baseApi + "/ietm/remarks/update",
      data: {
        "dataPacketFileName": dataPacketFileName,
        "dataModuleFileName": dataModuleFileName,
        "createBy": createBy,
        "remarksContent": content,
        "id": id
      },
      dataType: "JSON",
      success: function (res) {
        if (res.code == 200) {
          layer.msg("更新成功 !");
          // _this.parent(".bubble-btn").parent(".bubble").find(".bubble-id").val(res.data.id);
          _this.hide();
          // _this.prev(".delete").hide();
          _this.siblings(".delete, .hide").hide();
        } else {
          if (res.msg.includes("未登录")) {
            layer.msg('用户未登录!');
            setTimeout(function () {
              parent.parent.wlogout()
            }, 1500);
            return false;
          } else {
            layer.msg('更新失败 !');
          }
        }
      }, error: function (res) {
        layer.msg('请求失败 !');
      }
    })
  }
})

/* 初始化显示备注信息 */
initRemark();
function initRemark() {

  var createBy = localStorage.getItem("username");
  var dataPacketFileName = localStorage.getItem('dataPacketFileName');
  var dataModuleName = localStorage.getItem('dataModuleName');
  var dataModuleFileName = localStorage.getItem('dataModuleFileName');


  if (createBy == null || createBy == '') {
    createBy = "admin";
  }
  var url = baseApi + "/ietm/remarks/listByDataModule?t=" + (new Date()).getTime();
  $.ajax({
    type: "GET",
    url: url,
    data: {
      "dataPacketFileName": dataPacketFileName,
      "dataModuleFileName": dataModuleFileName,
      "createBy": createBy
    },
    dataType: "JSON",
    success: function (res) {
      if (res.code == 200) {
        var data = res.data;
        if (data.length > 0) {
          for (var i = 0; i < data.length; i++) {
            $("body").find("*").each(function () {
              // if(data[i].type == "0"){

              if ($(this).attr("ids") == data[i].remarksPosition) {
                if (data[i].remarksContent == null) {
                  data[i].remarksContent = "";
                }
                var bubble = '<div class="bubble" style="z-index:1;cursor: text;" id="' + data[i].remarksPosition + '">';
                bubble += '<input type="hidden" class="bubble-id" value="' + data[i].id + '"> ';
                bubble += '<div class="bubble-input" id="' + data[i].id + '" contenteditable="true" style="color:black;">' + data[i].remarksContent + '</div>';
                bubble += '<div class="bubble-btn">' +
                  '<button type="button" class="hide btn btn-lg btn-danger">隐藏</button>' +
                  '<button type="button" class="delete btn btn-lg btn-danger">' + i18n("i18n-lan-delete") + '</button>' +
                  '<button type="button" class="save btn btn-lg btn-success">' + i18n("i18n-lan-save") + '</button></div>';
                bubble += '</div>';
                $(this).append(bubble);
              }
              // }else{
              //     if ($(this).attr("ids") == data[i].remarksPosition) {
              //         initMark2($(this),data[i].remarksContent,data[i].id,data[i].remarksPosition);
              //     }
              // }
            })
          }

          var remarkId = sessionStorage.getItem("remarkId");
          // console.log(remarkId, 'remarkId');
          if (remarkId) {
            $(document).ready(function () {
              var iframeDocument = $(document)[0];
              if (iframeDocument) {
                var targetElement = iframeDocument.getElementById(remarkId);
                if (targetElement) {
                  targetElement.scrollIntoView();
                  sessionStorage.setItem("remarkId", '');
                }
              }
            });
          }

        }
      } else {
        if (res.msg.includes("未登录")) {
          layer.msg('用户未登录!');
          setTimeout(function () {
            parent.parent.wlogout()
          }, 1500);
          return false;
        } else {
          layer.msg(res.resp_msg);
        }
      }
    }, error: function (res) {
      layer.msg('请求失败 !');
    }
  })
}

// 获取焦点时存备注内容
let contentRemark = "";

/* 初始化备注获取焦点 */
focusRemark();
function focusRemark() {

  var createBy = localStorage.getItem("username");
  var dataPacketFileName = localStorage.getItem('dataPacketFileName');
  var dataModuleName = localStorage.getItem('dataModuleName');
  var dataModuleFileName = localStorage.getItem('dataModuleFileName');

  $("body").on("click", ".bubble .bubble-input,.bubble-btn", function (e) {
    //防止同类型事件同时执行
    e.stopImmediatePropagation();
  })
  $("body").on("focus", ".bubble .bubble-input", function () {
    clearTimeout(timeOutEvent);
    $(".bubble-btn>button").hide();
    $(this).parent(".bubble").find(".bubble-btn>button").show();
    if ($(this).html() !== "") {
      contentRemark = $(this).html();
    }
  })
  return
  $("body").on("blur", ".bubble .bubble-input", function (e) {
    //$(this).parent(".bubble").find(".bubble-btn>button").hide();
    var _this = $(this);
    console.log(!_this.prev(".bubble-id").attr('value'));
    console.log(_this.text() !== "");
    console.log(_this.text() !== contentRemark);
    if (!_this.prev(".bubble-id").attr('value') && _this.text() !== "" || _this.text() !== contentRemark) {
      console.log("asdasasdasd-------")
      contentRemark = "";
      //防止同类型事件同时执行
      e.stopImmediatePropagation();

      var url = baseApi + "gjbRemarks/save";
      var remarksPosition = $(this).parent(".bubble").attr("id");
      var remarkContent = $(this).parent(".bubble").parent().clone().children().remove().end().text();
      var content = $(this).html();
      var id = $(this).prev(".bubble-id").val();
      var type = '0';
      var modeType = sessionStorage.getItem("myScheme");
      var mic = sessionStorage.getItem("projectName");
      var pid = "";
      if (modeType == "0") {
        pid = sessionStorage.getItem("currentPid");
      } else {
        pid = sessionStorage.getItem("enterProjectId");
      }
      if (createBy == null || createBy == '') {
        createBy = "admin";
      }
      $.ajax({
        type: "POST",
        url: url,
        data: {
          "type": type,
          "dmc": dmc,
          "pid": pid,
          // "dmid":dmid,
          "remarkContent": remarkContent,
          "remarksPosition": remarksPosition,
          "content": content,
          "createBy": createBy,
          "id": id,
          "modeType": modeType,
          "mic": mic
        },
        dataType: "JSON",
        success: function (res) {
          if (res.resp_code == '0') {
            // layer.msg(i18n("i18n-lan-saveSuccess"));
            _this.prev(".bubble-id").val(res.datas.id);
            // _this.next().find(".hide").hide();
            // _this.next().find(".delete").hide();
            // _this.next().find(".save").hide();
          } else {
            layer.msg(res.resp_msg);
          }
        }, error: function (res) {

        }
      })
    }
  })

}

/* 隐藏备注 */
$("body").on("click", ".bubble-btn>.hide", function (e) {
  var _this = $(this);
  _this.parent(".bubble-btn").prev(".bubble-input").hide();
  _this.parent(".bubble-btn").css("text-align", "left").css("text-indent", "0");
  _this.siblings(".delete, .save").hide();
  _this.removeClass('hide').addClass('show').text('显示');
})

/* 显示备注 */
$("body").on("click", ".bubble-btn>.show", function (e) {
  var _this = $(this);
  _this.parent(".bubble-btn").prev(".bubble-input").show();
  _this.parent(".bubble-btn").css("text-align", "").css("text-indent", "");
  _this.siblings(".delete, .save").show();
  _this.removeClass('show').addClass('hide').text('隐藏');
})

/* 删除备注 */
$("body").on("click", ".bubble-btn>.delete", function (e) {

  var createBy = localStorage.getItem("username");
  var dataPacketFileName = localStorage.getItem('dataPacketFileName');
  var dataModuleName = localStorage.getItem('dataModuleName');
  var dataModuleFileName = localStorage.getItem('dataModuleFileName');

  //防止同类型事件同时执行
  e.stopImmediatePropagation();
  clearTimeout(timeOutEvent);

  var _this = $(this);
  layer.confirm(i18n("i18n-confirm-delete"), function (index) {
    var url = baseApi + "/ietm/remarks/delete";
    var id = _this.parent(".bubble-btn").parent(".bubble").find(".bubble-id").val();
    console.log(_this.parent(".bubble-btn").parent(".bubble"), _this.parent(".bubble-btn").parent(".bubble").find(".bubble-id"), id, ' 312830123018');
    // return false;
    $.ajax({
      type: "DELETE",
      url: url,
      data: {
        "isEmpty": 0,
        "id": id,
        "dataPacketFileName": dataPacketFileName,
        "dataModuleFileName": dataModuleFileName,
        "createBy": createBy
      },
      dataType: "JSON",
      success: function (res) {
        if (res.code == 200) {
          _this.parent(".bubble-btn").parent(".bubble").remove();
          layer.msg('删除成功！');
          layer.close(index);
        } else {
          if (res.msg.includes("未登录")) {
            layer.msg('用户未登录!');
            setTimeout(function () {
              parent.parent.wlogout()
            }, 1500);
            return false;
          } else {
            layer.msg('删除失败！');
          }
        }
      }, error: function (res) {
        layer.msg('请求失败 !');
      }
    })
  })
})

//xtt添加选中备注功能
var noRemarkNode = ["internalRef", "graphic", "dmRef", "bubble", "bubble-input", "headline", "stepheadline", "headline-text", "headline-icon", "menu_a", "menu_b", "menu_c", "menu_d", "context-menu"]
var remarkX = "";
var remarkY = ""
var openBiao = false;
document.onclick = function (e) {
  if (openBiao == true) {
    remarkX = e.clientX + $(window).scrollLeft();
    remarkY = e.clientY + $(window).scrollTop();
    //$('.context-menu').show().css({left: x, top: y});
    $(".domClickForRemark").removeClass("domClickForRemark");
    $ids = $(e.target);
    if ($.inArray($ids.attr("class"), noRemarkNode) > -1 || $.inArray($ids.parent().parent().attr("class"), noRemarkNode) > -1) {
      $ids = "";
      return false;

    } else {
      $ids.addClass("domClickForRemark");
      $('.context-menu').show().css({ left: remarkX, top: remarkY });
    }
  }
}

function showContentMenu() {
  openBiao = true;
}

function hideContentMenu() {
  openBiao = false;
  $(".domClickForRemark").removeClass("domClickForRemark");
}


//点击红线标记按钮选项
$(".context-menu .menu_f").on("click", function () {
  if ($($ids).children().length > 0) {
    //元素限制的class，[页面空白等，热点，table热点，SVG图片DIV，SVG图片，table，备注，备注内容，headline标题等]
    var noRedLineNode = ["lbody", "content", "internalRef", "dmCode", "graphic-div", "graphic", "dmRef", "bubble", "bubble-input", "headline", "headline-content",
      "headline-title", "headline-status", "headline-text", "headline-icon", "relation", "relationTitle", "relationSpan", "DmMedialist_div_titlle", "layui-timeline-item"]

    //限制不能被标注的元素--多元素限制
    if ($.inArray($ids.attr("class"), noRedLineNode) > -1 || $.inArray($ids.parent().parent().attr("class"), noRedLineNode) > -1) {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "A") {//元素是A或SVG图片或按钮标签，无class用来限制
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "IMG") {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "BUTTON") {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "THEAD" || $($ids).prop("nodeName") == "TH") {//元素是table的头部标签，无class用来限制
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else {
      if ($($ids).children().length == 1) {//只有一个元素
        //是internalRef的A标签
        if ($($ids).children(0).prop("nodeName") == "A" && $($ids).children(0).hasClass("internalRef")) {
          $('.context-menu').hide();
          layer.msg(i18n("i18n-alert-noReadMark"));
          return false;
        } else if ($($ids).children(0).prop("nodeName") == "A" && $($ids).children(0).hasClass("popable")) {
          $('.context-menu').hide();
          layer.msg(i18n("i18n-alert-noReadMark"));
          return false;
        } else if ($($ids).children(0).prop("nodeName") == "SPAN" && $($ids).children(0).hasClass("dmRef")) {
          $('.context-menu').hide();
          layer.msg(i18n("i18n-alert-noReadMark"));
          return false;
        }
      }
      //调用红线标记保存接口,页面元素--红线内容
      // Mark($($ids),$($ids).html());
    }
  } else {
    //元素限制的class，[页面空白等，热点，table热点，SVG图片DIV，SVG图片，table，备注，备注内容，headline标题等]
    var noRedLineNode = ["lbody", "content", "internalRef", "dmCode", "graphic-div", "graphic", "dmRef", "bubble", "bubble-input", "headline", "headline-content",
      "headline-title", "headline-status", "headline-text", "headline-icon", "relation", "relationTitle", "relationSpan", "DmMedialist_div_titlle", "layui-timeline-item"]
    //限制不能被标注的元素--单元素限制
    if ($.inArray($ids.attr("class"), noRedLineNode) > -1 || $.inArray($ids.parent().parent().attr("class"), noRedLineNode) > -1) {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "A") {//元素是A或SVG图片或按钮标签，无class用来限制
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "IMG") {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "BUTTON") {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).prop("nodeName") == "THEAD" || $($ids).prop("nodeName") == "TH") {//元素是table的头部标签，无class用来限制
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else if ($($ids).html() == "&nbsp;" || $($ids).html().length == 0) {
      $('.context-menu').hide();
      layer.msg(i18n("i18n-alert-noReadMark"));
      return false;
    } else {
      //调用红线标记保存接口,页面元素--红线内容--无子元素
      // Mark($($ids),$($ids).html());
    }
  }
})

//红线保存后显示
function initMark($Para, txt, id, ids) {
  var html = $Para.html();
  html = html.replaceAll(txt, '<span type="text/html" style="text-decoration:none;color: red" class="custom-underline" mark="' + id + '">' + txt + '</span>');
  $Para.html(html);
}

//红线页面刷新显示
function initMark2($Para, txt, id, ids) {
  //获取选中ids标签
  var idsElement = $("*[ids$='" + ids + "']");
  //判断选中标签是否是SPAN
  if (idsElement.children(0).prop("nodeName") != "SPAN" || idsElement.children(0).attr("mark") != undefined) {
    //给数据添加红线
    var idsElementHtml = idsElement.html();
    idsElement.html('<span type="text/html" style="text-decoration:none;color: red" class="custom-underline" mark="' + id + '">' + idsElementHtml + '</span>');
  }
}

//显示更改标记
$(".context-menu .menu_e").on("click", function () {
  if ($(this).text() == "显示更改" || $(this).text().trim() == "Display Changes") {
    $(this).text(i18n("i18n-lan-hideUpdate"))
    showUpdateLog();
  } else {
    $(this).text(i18n("i18n-lan-showUpdate"))
    hideUpdateLog();
  }
})


$(".context-menu .menu_g").on("click", function () {
  $(".content1").css({ "width": "50%", "display": "inline-block" });
  $(".content2").css({ "width": "50%", "display": "inline-block" });
  $(".description").css({ "margin-left": "30px", "margin-right": "0px", });
})
$(function () {
  //高亮显示 1
  $('.content2 ul').on('mouseenter', 'li', function () {//绑定鼠标进入事件
    $(this).addClass('bkyColor');
    console.log($(".content1 #" + $(this).attr("id")))
    $(".content1 #" + $(this).attr("id")).addClass('bkyColor');
  });
  $('.content2 ul').on('mouseleave', 'li', function () {//绑定鼠标划出事件
    $(this).removeClass('bkyColor');
    $(".content1 #" + $(this).attr("id")).removeClass('bkyColor');
  });
});

$(document).ready(function () {
  var isMessage = sessionStorage.getItem("isMessage");
  var messageId = sessionStorage.getItem("messageId");
  // console.log(messageId, 'messageIdmessageIdmessageId');
  if (isMessage && isMessage === 'true') {
    parent.openMessage(messageId);
    sessionStorage.setItem("isMessage", false);
    sessionStorage.removeItem("messageId");
  }
})
















